.class public final Llt/noframe/gpsfarmguide/database/DatabaseBackup;
.super Ljava/lang/Object;
.source "DatabaseBackup.kt"


# static fields
.field public static final INSTANCE:Llt/noframe/gpsfarmguide/database/DatabaseBackup;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .line 16
    new-instance v0, Llt/noframe/gpsfarmguide/database/DatabaseBackup;

    invoke-direct {v0}, Llt/noframe/gpsfarmguide/database/DatabaseBackup;-><init>()V

    sput-object v0, Llt/noframe/gpsfarmguide/database/DatabaseBackup;->INSTANCE:Llt/noframe/gpsfarmguide/database/DatabaseBackup;

    return-void
.end method

.method private constructor <init>()V
    .locals 0

    .line 16
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public final copy(Ljava/io/File;Ljava/io/File;)V
    .locals 3
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const-string v0, "input"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string v0, "output"

    invoke-static {p2, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 69
    :try_start_0
    new-instance v0, Ljava/io/FileInputStream;

    invoke-direct {v0, p1}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V

    .line 70
    new-instance p1, Ljava/io/FileOutputStream;

    invoke-direct {p1, p2}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V

    const/16 p2, 0x400

    .line 73
    new-array p2, p2, [B

    const/4 v1, -0x1

    :cond_0
    if-lez v1, :cond_1

    const/4 v2, 0x0

    .line 78
    invoke-virtual {p1, p2, v2, v1}, Ljava/io/FileOutputStream;->write([BII)V

    .line 80
    :cond_1
    invoke-virtual {v0, p2}, Ljava/io/FileInputStream;->read([B)I

    move-result v1

    if-gtz v1, :cond_0

    .line 84
    invoke-virtual {p1}, Ljava/io/FileOutputStream;->flush()V

    .line 85
    invoke-virtual {p1}, Ljava/io/FileOutputStream;->close()V

    .line 86
    invoke-virtual {v0}, Ljava/io/FileInputStream;->close()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception p1

    .line 88
    invoke-virtual {p1}, Ljava/lang/Exception;->printStackTrace()V

    :goto_0
    return-void
.end method

.method public final onResultFromActivity(Landroid/app/Activity;IILandroid/content/Intent;)Z
    .locals 8

    const-string v0, "activity"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const/4 v0, 0x0

    const/4 v1, -0x1

    if-ne p3, v1, :cond_2

    if-eqz p4, :cond_2

    .line 24
    sget p3, Llt/noframe/gpsfarmguide/views/ActivityDrawer;->REQUEST_SELECT_BACKUP_RESTORE_PLACE:I

    const-string v1, "activity.getDatabasePath(DB.DATABASE_NAME)"

    const-string v2, "allAreas"

    const-string v3, "data.getStringExtra(File\u2026ctivity.RESULT_FILE_PATH)"

    const-string v4, "result_file_path"

    const/4 v5, 0x1

    if-ne p2, p3, :cond_1

    .line 25
    invoke-virtual {p4, v4}, Landroid/content/Intent;->getStringExtra(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p2

    invoke-static {p2, v3}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string p3, "temp"

    .line 27
    invoke-virtual {p1, p3}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p4

    invoke-virtual {p4}, Ljava/io/File;->delete()Z

    .line 28
    new-instance p4, Ljava/io/File;

    invoke-direct {p4, p2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {p1, p3}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p2

    const-string v0, "activity.getDatabasePath(\"temp\")"

    invoke-static {p2, v0}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    invoke-virtual {p0, p4, p2}, Llt/noframe/gpsfarmguide/database/DatabaseBackup;->copy(Ljava/io/File;Ljava/io/File;)V

    .line 31
    :try_start_0
    new-instance p2, Llt/noframe/gpsfarmguide/database/DB;

    invoke-direct {p2, p1, p3}, Llt/noframe/gpsfarmguide/database/DB;-><init>(Landroid/content/Context;Ljava/lang/String;)V

    .line 32
    invoke-virtual {p2}, Llt/noframe/gpsfarmguide/database/DB;->validateDb()Z

    move-result p2

    if-eqz p2, :cond_0

    .line 36
    invoke-static {}, Llt/noframe/gpsfarmguide/database/DB;->getDB()Llt/noframe/gpsfarmguide/database/DB;

    move-result-object p2

    invoke-virtual {p2}, Llt/noframe/gpsfarmguide/database/DB;->close()V

    .line 37
    invoke-virtual {p1, p3}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p2

    invoke-static {p2, v0}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    invoke-virtual {p1, v2}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p4

    invoke-static {p4, v1}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    invoke-virtual {p0, p2, p4}, Llt/noframe/gpsfarmguide/database/DatabaseBackup;->copy(Ljava/io/File;Ljava/io/File;)V

    const p2, 0x7f1100b6

    .line 38
    invoke-virtual {p1, p2}, Landroid/app/Activity;->getString(I)Ljava/lang/String;

    move-result-object p2

    invoke-static {p1, p2, v5}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object p2

    invoke-virtual {p2}, Landroid/widget/Toast;->show()V

    goto :goto_0

    .line 33
    :cond_0
    new-instance p2, Ljava/lang/RuntimeException;

    const-string p4, "Invalid db"

    invoke-direct {p2, p4}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw p2
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :catch_0
    move-exception p2

    .line 40
    invoke-virtual {p2}, Ljava/lang/Exception;->printStackTrace()V

    const p2, 0x7f1100cb

    .line 41
    invoke-virtual {p1, p2}, Landroid/app/Activity;->getString(I)Ljava/lang/String;

    move-result-object p2

    invoke-static {p1, p2, v5}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object p2

    invoke-virtual {p2}, Landroid/widget/Toast;->show()V

    .line 43
    :goto_0
    invoke-virtual {p1, p3}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p1

    invoke-virtual {p1}, Ljava/io/File;->delete()Z

    return v5

    .line 46
    :cond_1
    sget p3, Llt/noframe/gpsfarmguide/views/ActivityDrawer;->REQUEST_SELECT_BACKUP_SAVE_PLACE:I

    if-ne p2, p3, :cond_2

    .line 47
    invoke-virtual {p4, v4}, Landroid/content/Intent;->getStringExtra(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p2

    invoke-static {p2, v3}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 48
    new-instance p3, Ljava/lang/StringBuilder;

    invoke-direct {p3}, Ljava/lang/StringBuilder;-><init>()V

    const-string p4, "Navigator_backup_"

    invoke-virtual {p3, p4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v3

    const/16 p4, 0x3e8

    int-to-long v6, p4

    div-long/2addr v3, v6

    invoke-virtual {p3, v3, v4}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    const-string p4, ".ffndb"

    invoke-virtual {p3, p4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {p3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p3

    .line 50
    invoke-virtual {p1, v2}, Landroid/app/Activity;->getDatabasePath(Ljava/lang/String;)Ljava/io/File;

    move-result-object p4

    invoke-static {p4, v1}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    new-instance v1, Ljava/io/File;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v2, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    sget-char p2, Ljava/io/File;->separatorChar:C

    invoke-virtual {v2, p2}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    invoke-virtual {v2, p3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p2

    invoke-direct {v1, p2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0, p4, v1}, Llt/noframe/gpsfarmguide/database/DatabaseBackup;->copy(Ljava/io/File;Ljava/io/File;)V

    const p2, 0x7f110034

    .line 51
    new-array p4, v5, [Ljava/lang/Object;

    aput-object p3, p4, v0

    invoke-virtual {p1, p2, p4}, Landroid/app/Activity;->getString(I[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object p2

    invoke-static {p1, p2, v5}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object p1

    invoke-virtual {p1}, Landroid/widget/Toast;->show()V

    return v5

    :cond_2
    return v0
.end method
